/**
 * 
 */
package travibot.ui.gui.forms;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.SWT;

import travibot.ui.gui.StatusNotification;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Display;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * @author tajzivit
 *
 */
public class StatusBar extends Composite {

    private static final int NOTIFICATION_FIELDS_HEIGHT = 20;
    
    private StyledText leftStyledText = null;
    private StyledText middleStyledText = null;
    private StyledText rightStyledText = null;

    public StatusBar(Composite parent, int style) {

        super(parent, style);
        initialize();
    }

    private void initialize() {

        GridData middleLData = new GridData();
        middleLData.horizontalAlignment = GridData.FILL;  // Generated
        middleLData.grabExcessHorizontalSpace = true;  // Generated
        middleLData.heightHint = NOTIFICATION_FIELDS_HEIGHT;
        GridData leftLData = new GridData();
        leftLData.grabExcessHorizontalSpace = true;  // Generated
        leftLData.horizontalAlignment = GridData.FILL;  // Generated
        leftLData.heightHint = NOTIFICATION_FIELDS_HEIGHT;
        GridData rightLData = new GridData();
        rightLData.horizontalAlignment = GridData.FILL;  // Generated
        rightLData.grabExcessHorizontalSpace = true;  // Generated
        rightLData.heightHint = NOTIFICATION_FIELDS_HEIGHT;
        GridLayout layout = new GridLayout();
        layout.numColumns = 3;  // Generated
        layout.verticalSpacing = 0;
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        layout.horizontalSpacing = 0;
        leftStyledText = new StyledText(this, SWT.SINGLE);
        leftStyledText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        leftStyledText.setLayoutData(leftLData);  // Generated
        middleStyledText = new StyledText(this, SWT.SINGLE);
        middleStyledText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        middleStyledText.setLayoutData(middleLData);  // Generated
        rightStyledText = new StyledText(this, SWT.SINGLE);
        rightStyledText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        rightStyledText.setLayoutData(rightLData);  // Generated
        this.setLayout(layout);  // Generated
        setSize(new Point(600, 48));
    }

    public void showNotification(StatusNotification statusNotification){
        
        leftStyledText.setText(statusNotification.getStatus().toString());;
        
        if(!isEmpty(statusNotification.getMessage()))
            middleStyledText.setText(statusNotification.getMessage());
        
        if(!isEmpty(statusNotification.getAdditionalMessage()))
            rightStyledText.setText(statusNotification.getAdditionalMessage());
        
    }
    
    private boolean isEmpty(String s){
        
        return (s == null || s.equals(""));
    }
}  //  @jve:decl-index=0:visual-constraint="10,10"
